//
//  YZESuifangTimeTypeCell.m
//  yilutongxing
//
//  Created by T&J on 2017/6/5.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "YZESuifangTimeTypeCell.h"
#import "Masonry.h"

@interface YZESuifangTimeTypeCell ()

@property (nonatomic, strong) NSArray *btnArr;

@end

@implementation YZESuifangTimeTypeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    NSArray *titleArr = @[@" 一个月内\n(每周一次)", @" 三个月内\n(每周一次)",@"   半年内\n(每月一次)",
                          @"      半年后\n(每两个月一次)", @"     一年以上\n(每三个月一次)", @"其它"];
    self.btnArr = @[self.btn1, self.btn2, self.btn3, self.btn4, self.btn5, self.btn6];
    for (int i=0; i<self.btnArr.count; i++) {
        UIButton *btn = self.btnArr[i];
        btn.layer.cornerRadius = btn.height/2;
        btn.layer.masksToBounds = btn.height/2;
        btn.layer.borderColor = COLOR(240, 240, 240).CGColor;
        btn.layer.borderWidth = 1;
        btn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        btn.titleLabel.font = [UIFont systemFontOfSize:12.0];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)btnclick:(id)sender {
    UIButton *btn = (UIButton*)sender;
    if (!btn.selected) {
        for (UIButton *others in self.btnArr) {
            if (others.tag!=btn.tag) {
                others.selected = NO;
            }
        }
    }
    if (btn!=_btn6) {
        btn.selected = !btn.selected;
    }
    else {
        btn.selected = YES;
    }
    
    NSLog(@"btn%ld clicked!", (long)btn.tag);
}

-(void)updateConstraints{
    if (SCREEN_WIDTH==320) {
        [self.btn1 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.label_title.mas_bottom).with.offset(10);
            make.left.mas_equalTo(16);
        }];
        [self.btn2 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn1);
            make.left.mas_equalTo(self.btn1.mas_right).with.offset(10);
        }];
        [self.btn3 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.btn1);
            make.top.mas_equalTo(self.btn1.mas_bottom).with.offset(10);
        }];
        [self.btn4 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn3);
            make.left.mas_equalTo(self.btn3.mas_right).with.offset(10);
        }];
        [self.btn5 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.btn3);
            make.top.mas_equalTo(self.btn3.mas_bottom).with.offset(10);
        }];
        [self.btn6 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.btn5.mas_right).with.offset(10);
            make.top.mas_equalTo(self.btn5);
        }];
    }
    else {
        [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.label_title.mas_bottom).offset(10);
            make.left.mas_equalTo(16);
        }];
        [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn1.mas_top);
            make.left.mas_equalTo(self.btn1.mas_right).offset(8);
        }];
        [self.btn3 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.btn2.mas_right).offset(8);
            make.top.mas_equalTo(self.btn2.mas_top);
        }];
        [self.btn4 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn3.mas_bottom).offset(10);
            make.left.mas_equalTo(self.btn1.mas_left);
        }];
        [self.btn5 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn4.mas_top);
            make.left.mas_equalTo(self.btn4.mas_right).offset(10);
        }];
        [self.btn6 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.btn5.mas_right).offset(10);
            make.top.mas_equalTo(self.btn5.mas_top);
        }];
    }
    [super updateConstraints];
}


@end
